package com.zym.controller.common.slidercaptcha;


import cloud.tianai.captcha.common.constant.CaptchaTypeConstant;
import cloud.tianai.captcha.spring.application.ImageCaptchaApplication;
import cloud.tianai.captcha.spring.vo.CaptchaResponse;
import cloud.tianai.captcha.spring.vo.ImageCaptchaVO;
import cloud.tianai.captcha.validator.common.model.dto.ImageCaptchaTrack;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Api(tags = "滑动验证码")
@RestController
public class SliderCaptchaController {

    @Autowired
    private ImageCaptchaApplication application;
    @GetMapping("/gen")
    public CaptchaResponse<ImageCaptchaVO> genCaptcha(HttpServletRequest request, @RequestParam(value = "type", required = false)String type) {
        if (StringUtils.isBlank(type)) {
            type = CaptchaTypeConstant.SLIDER;
        }
        CaptchaResponse<ImageCaptchaVO> response = application.generateCaptcha(type);
        return response;
    }

    @PostMapping("/check")
    public Map<String,Object> checkCaptcha(@RequestParam("id") String id,
                                @RequestBody ImageCaptchaTrack imageCaptchaTrack,
                                HttpServletRequest request) {

        boolean matching = application.matching(id, imageCaptchaTrack);
        Map<String,Object> map=new HashMap<>();
        if (matching){
            map.put("code",200);
            return map;
        }
        map.put("code",500);
        return map;
    }
    @PostMapping("/check1")
    public String checkCaptcha(@RequestParam("id") String id) {

        return "map"+id;
    }




}
